// https://leetcode.cn/problems/shortest-distance-to-a-character/
// Created by ade on 2022/8/17.
//
#include <iostream>
#include <vector>
#include <string>


using namespace std;

class Solution {
public:
    vector<int> shortestToChar(string s, char c) {
        int prev = -10000;
        int cur = s.find_first_of(c);
        int len = s.size();
        vector<int> pos(len);
        for (int i = 0; i < len; i++) {
            if (cur == string::npos) {
                pos[i] = i - prev;
            } else if (cur > i) {
                pos[i] = min(i - prev, cur - i);
            } else if (cur == i) {
                prev = cur;
                cur = s.find_first_of(c, cur + 1);
            }
        }
        return pos;
    }
};

int main() {
    Solution so;
    string s = "loveleetcode";
    char c = 'e';
    auto res = so.shortestToChar(s, c);
    for (auto i : res) {
        cout << i << ",";
    }
    cout << endl;
    return 0;
}